package com.apexsoft.test.sample.ams.producer;

import com.apexsoft.aas.service.annotations.ABusiness;
import com.apexsoft.aas.service.annotations.AService;
import com.apexsoft.aas.service.model.*;

import java.io.*;

/**
 * @Author: initializr
 * @Description:
 * @Date: Created in 2019-10-23 13:43
 * @MODIFIED BY:
 */
@ABusiness(namespace = "test", pkg = "upload")
public class AUploadProducerDemo {

    @AService(name = "service")
    public AUploadResponse service1(AUploadRequest req) throws IOException {
        File file = new File("new" + req.getFileInfo().getFileName());
        if (!file.exists()) {
            file.createNewFile();
        }

        try (FileOutputStream fos = new FileOutputStream(file);
             InputStream fis = req.getInputStream()) {
            byte[] bytes = new byte[fis.available()];
            fis.read(bytes);
            fos.write(bytes);
        }

        AUploadResponse response = new AUploadResponse();
        response.setCode(1);
        response.setNote("上传成功");
        response.addData("222",2222);
        return response;

    }


}
